# _*_ coding:utf-8 _*_
# @Time : 2021/9/17 17:49
# @Author : wsl
# @File : Urllib
# @Project : python  get请求 获取豆瓣电影第一页/前n页数据保存

import urllib.request
import urllib.parse

# page   1  2   3   4
# start  0  20  40  60
# start = (page-1)*20

base_url = 'https://movie.douban.com/j/chart/top_list?type=5&interval_id=100%3A90&action=&start=0&limit=20'
# base_url = 'https://movie.douban.com/j/chart/top_list?type=5&interval_id=100%3A90&action=&start=20&limit=20'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0'
}

request = urllib.request.Request(url=base_url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
print(content)
# 默认是gbk
# fp = open('../image/output/douban.test.json', 'w', encoding='utf-8')
# fp.write(content)

with open('../image/output/douban2.test.json', 'w', encoding='utf-8') as fp:
    fp.write(content)
